import React from 'react';
import objectAssign from 'object-assign';

export default function WeaCircleImage(props) {
  const { diameter = 0, name, src, style } = props,
    imgStyle = {
      width: diameter,
      height: diameter,
      borderRadius: diameter / 2,
      display: 'inline-block',
      verticalAlign: 'middle',
    },
    spanStyle = {
      width: diameter,
      height: diameter,
      borderRadius: diameter / 2,
      display: 'inline-block',
      verticalAlign: 'middle',

      fontSize: diameter * 0.25,
      background: '#32a8ff',
      color: 'white',
      textAlign: 'center',
      lineHeight: `${diameter}px`,
    };
  let reg = /^\s+|\s+$/g;
  let currentName = name.replace(reg, '').substring(0, 1).toUpperCase();
  return src ? (
    <img src={src} style={objectAssign({}, imgStyle, { ...style })} />
  ) : (
    <span style={objectAssign({}, spanStyle, { ...style })}>{currentName}</span>
  );
}
